<template>
    <div>
        <el-dialog
            title="提示"
            :visible="true"
            width="30%"
            :before-close="handleClose">
            <div>
                <el-form ref="subFormRef" :model="subForm">
                    <el-form-item v-for="(item, index) in curRowCompData" :key="index" :prop="item.__vModel__" :label="item.__config__.label">
                        <render :key="item.__config__.renderKey" :conf="item" @input="e => changeInput(e, index, item)"/>
                    </el-form-item>
                </el-form>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="handleClose" size="small">取 消</el-button>
                <el-button type="primary" @click="confirm" size="small">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
import render from '@/components/render/render.js'
export default {
    name: 'SubFormEditDialog',
    data () {
        return  {
            subForm: {}
        }
    },
    components: {
        render
    },
    props: ['curRowCompData', 'config', 'curRowNum', 'tableIndex'],
    wactch: {
        curRowCompData (newVal, oldVal) {
            console.table(newVal)
        }
    },
    created () {
        this.subForm.curRowNum = this.curRowNum
        this.subForm.tableIndex = this.tableIndex
    },
    methods: {
        changeInput (e, index, item) {
            // 更改配置数据
            this.$set(item.__config__, 'defaultValue', e)
        },
        confirm () {
            this.curRowCompData.forEach(cur => {
                this.subForm[cur.__vModel__] = cur.__config__.defaultValue
            })
            this.$emit('confirm', this.subForm)
        },
        handleClose() {
            this.$emit('cancel')
        }
    },
}
</script>